home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / gradti_1 / frmgradt.frm (.txt) next >
Encoding:
Visual Basic Form  |  1998-06-08  |  11.9 KB  |  352 lines

  1. VERSION 5.00
  2. Begin VB.Form frmGradTitle 
  3.    BorderStyle     =   0  'None
  4.    Caption         =   "Gradient TitleBar"
  5.    ClientHeight    =   5715
  6.    ClientLeft      =   2130
  7.    ClientTop       =   2355
  8.    ClientWidth     =   6630
  9.    Icon            =   "frmGradTitle.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5715
  12.    ScaleWidth      =   6630
  13.    Begin VB.PictureBox picTitleBar 
  14.       AutoRedraw      =   -1  'True
  15.       BorderStyle     =   0  'None
  16.       Height          =   280
  17.       Left            =   20
  18.       ScaleHeight     =   285
  19.       ScaleWidth      =   6480
  20.       TabIndex        =   1
  21.       Top             =   20
  22.       Width           =   6480
  23.       Begin VB.Image imgMaximize 
  24.          Height          =   210
  25.          Left            =   5880
  26.          Picture         =   "frmGradTitle.frx":0442
  27.          Top             =   30
  28.          Width           =   240
  29.       End
  30.       Begin VB.Image imgMinimize 
  31.          Height          =   210
  32.          Left            =   5640
  33.          Picture         =   "frmGradTitle.frx":0724
  34.          Top             =   30
  35.          Width           =   240
  36.       End
  37.       Begin VB.Image imgCloseForm 
  38.          Height          =   210
  39.          Left            =   6240
  40.          Picture         =   "frmGradTitle.frx":0A06
  41.          Top             =   30
  42.          Width           =   240
  43.       End
  44.       Begin VB.Image imgFormIcon 
  45.          Height          =   240
  46.          Left            =   60
  47.          Stretch         =   -1  'True
  48.          Top             =   20
  49.          Width           =   240
  50.       End
  51.       Begin VB.Label lblFormCaption 
  52.          BackStyle       =   0  'Transparent
  53.          Caption         =   "Form Caption"
  54.          ForeColor       =   &H00FFFFFF&
  55.          Height          =   255
  56.          Left            =   360
  57.          TabIndex        =   2
  58.          Top             =   30
  59.          Width           =   3975
  60.       End
  61.    End
  62.    Begin VB.CommandButton cmdDummy 
  63.       Caption         =   "Command1"
  64.       Height          =   195
  65.       Left            =   2880
  66.       TabIndex        =   0
  67.       Top             =   60
  68.       Width           =   75
  69.    End
  70.    Begin VB.Line lineBorder1 
  71.       X1              =   0
  72.       X2              =   0
  73.       Y1              =   0
  74.       Y2              =   5640
  75.    End
  76.    Begin VB.Line lineBorder2 
  77.       X1              =   0
  78.       X2              =   6600
  79.       Y1              =   0
  80.       Y2              =   0
  81.    End
  82.    Begin VB.Line lineBorder3 
  83.       X1              =   6600
  84.       X2              =   6600
  85.       Y1              =   5640
  86.       Y2              =   0
  87.    End
  88.    Begin VB.Line lineBorder4 
  89.       X1              =   0
  90.       X2              =   6600
  91.       Y1              =   5640
  92.       Y2              =   5640
  93.    End
  94.    Begin VB.Image imgMaximizeButton 
  95.       Height          =   210
  96.       Left            =   3360
  97.       Picture         =   "frmGradTitle.frx":0CE8
  98.       Top             =   60
  99.       Width           =   240
  100.    End
  101.    Begin VB.Image imgNormalizeButton 
  102.       Height          =   210
  103.       Left            =   3600
  104.       Picture         =   "frmGradTitle.frx":0FCA
  105.       Top             =   60
  106.       Width           =   240
  107.    End
  108.    Begin VB.Image imgCloseFormButton 
  109.       Height          =   210
  110.       Left            =   3840
  111.       Picture         =   "frmGradTitle.frx":12AC
  112.       Top             =   60
  113.       Width           =   240
  114.    End
  115.    Begin VB.Image imgCloseFormButtonDown 
  116.       Height          =   210
  117.       Left            =   4800
  118.       Picture         =   "frmGradTitle.frx":158E
  119.       Top             =   60
  120.       Width           =   240
  121.    End
  122.    Begin VB.Image imgNormalizeButtonDown 
  123.       Height          =   210
  124.       Left            =   4560
  125.       Picture         =   "frmGradTitle.frx":1870
  126.       Top             =   60
  127.       Width           =   240
  128.    End
  129.    Begin VB.Image imgMaximizeButtonDown 
  130.       Height          =   210
  131.       Left            =   4320
  132.       Picture         =   "frmGradTitle.frx":1B52
  133.       Top             =   60
  134.       Width           =   240
  135.    End
  136.    Begin VB.Image imgMinimizeButtonDown 
  137.       Height          =   210
  138.       Left            =   4080
  139.       Picture         =   "frmGradTitle.frx":1E34
  140.       Top             =   60
  141.       Width           =   240
  142.    End
  143.    Begin VB.Image imgMinimizeButton 
  144.       Height          =   210
  145.       Left            =   3120
  146.       Picture         =   "frmGradTitle.frx":2116
  147.       Top             =   60
  148.       Width           =   240
  149.    End
  150. Attribute VB_Name = "frmGradTitle"
  151. Attribute VB_GlobalNameSpace = False
  152. Attribute VB_Creatable = False
  153. Attribute VB_PredeclaredId = True
  154. Attribute VB_Exposed = False
  155. Option Explicit
  156. Private IsMaximized As Boolean
  157. Private IsMinimized As Boolean
  158. Private ButtonsCount As Integer
  159. Private Sub Form_Paint()
  160.     ReSize
  161.     EndFRDrag Me.Top, Me.Left
  162. End Sub
  163. Private Sub imgCloseForm_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  164.     imgCloseForm.Picture = imgCloseFormButtonDown.Picture
  165. End Sub
  166. Private Sub imgCloseForm_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  167.   ' Unload All of the Forms
  168.   Dim frm As Form
  169.     imgCloseForm.Picture = imgCloseFormButton.Picture
  170.     For Each frm In Forms
  171.         Unload frm
  172.     Next frm
  173.     End
  174. End Sub
  175. Private Sub imgMaximize_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  176.     If IsMaximized = True Then
  177.         imgMaximize.Picture = imgNormalizeButtonDown.Picture
  178.     Else
  179.         imgMaximize.Picture = imgMaximizeButtonDown.Picture
  180.     End If
  181. End Sub
  182. Private Sub imgMaximize_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  183.     If IsMaximized = False Then
  184.         Me.WindowState = 2
  185.         IsMaximized = True
  186.         Form_Resize
  187.         imgMaximize.Picture = imgNormalizeButton.Picture
  188.     Else
  189.         Me.WindowState = 0
  190.         IsMaximized = False
  191.         Form_Resize
  192.         imgMaximize.Picture = imgMaximizeButton.Picture
  193.     End If
  194. End Sub
  195. Private Sub imgMinimize_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  196.     imgMinimize.Picture = imgMinimizeButtonDown.Picture
  197. End Sub
  198. Private Sub imgMinimize_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  199.     If IsMinimized = False Then
  200.         Me.WindowState = 1
  201.         IsMinimized = True
  202.         Form_Resize
  203.         imgMinimize.Picture = imgMinimizeButton.Picture
  204.     Else
  205.         Me.WindowState = 0
  206.         IsMinimized = False
  207.         Form_Resize
  208.         imgMinimize.Picture = imgMinimizeButton.Picture
  209.     End If
  210. End Sub
  211. Private Sub Form_Activate()
  212.     IsMinimized = False
  213. End Sub
  214. Private Sub Form_Load()
  215.   Dim frameHeight As Long
  216.   Dim frameWidth As Long
  217.     Me.ScaleMode = 3
  218.        '     'compute the width of the left and right dialog frame
  219.     frameHeight = GetSystemMetrics(SM_CYDLGFRAME) * 2
  220.        '     'compute the width of the top and bottom dialog frame
  221.     frameWidth = GetSystemMetrics(SM_CXDLGFRAME) * 2
  222.        
  223.     Me.ScaleMode = 1
  224.     ButtonsCount = 0
  225.     If Me.MaxButton = True Then ButtonsCount = ButtonsCount + 1
  226.     If Me.MinButton = True Then ButtonsCount = ButtonsCount + 2
  227.     Select Case ButtonsCount
  228.         Case 0
  229.             imgMaximize.Visible = False
  230.             imgMinimize.Visible = False
  231.         Case 1
  232.             imgMinimize.Visible = False
  233.         Case 2
  234.             imgMaximize.Visible = False
  235.     End Select
  236.     ReSize
  237.     DrawCaption Me.Caption
  238.     imgFormIcon.Picture = Me.Icon
  239. End Sub
  240. Private Sub Form_Resize()
  241.     ReSize
  242. End Sub
  243. Private Sub picTitleBar_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  244.     BeginFRDrag x, y
  245. End Sub
  246. Private Sub picTitleBar_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  247.     If Button = 1 Then DoFRDrag x, y
  248. End Sub
  249. Private Sub picTitleBar_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  250.     EndFRDrag x, y
  251. End Sub
  252. Private Sub lblFormCaption_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
  253.     BeginFRDrag x, y
  254. End Sub
  255. Private Sub lblFormCaption_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
  256.     If Button = 1 Then DoFRDrag x, y
  257. End Sub
  258. Private Sub lblFormCaption_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
  259.     EndFRDrag x, y
  260. End Sub
  261. Private Sub BeginFRDrag(x As Single, y As Single)
  262.     If IsMaximized = True Then Exit Sub
  263.     If IsMinimized = True Then Exit Sub
  264.        Dim tDc As Long
  265.        Dim sDc As Long
  266.        Dim d As Long
  267.        '     'convert points to POINTAPI struct
  268.        dpoint.x = x
  269.        dpoint.y = y
  270.        '     'get screen area of Me
  271.        GetWindowRect Me.hWnd, fbox 'screen Rect of Me
  272.        TwipsPerPixelX = Screen.TwipsPerPixelX
  273.        TwipsPerPixelY = Screen.TwipsPerPixelY
  274.        '     'get point of mousedown in screen coordinates
  275.        temp = dpoint
  276.        ClientToScreen Me.hWnd, temp
  277.        sDc = GetDC(ByVal 0)
  278.        DrawFocusRect sDc, tbox
  279.        d = ReleaseDC(0, sDc)
  280.        oldbox = tbox
  281. End Sub
  282. Private Sub DoFRDrag(x As Single, y As Single)
  283.     If IsMaximized = True Then Exit Sub
  284.     If IsMinimized = True Then Exit Sub
  285.        Dim tDc As Long
  286.        Dim sDc As Long
  287.        Dim d As Long
  288.        tpoint.x = x
  289.        tpoint.y = y
  290.        ClientToScreen Me.hWnd, tpoint
  291.        tbox.Left = (fbox.Left + tpoint.x / TwipsPerPixelX) - temp.x / TwipsPerPixelX
  292.        tbox.Top = (fbox.Top + tpoint.y / TwipsPerPixelY) - temp.y / TwipsPerPixelY
  293.        tbox.Right = (fbox.Right + tpoint.x / TwipsPerPixelX) - temp.x / TwipsPerPixelX
  294.        tbox.Bottom = (fbox.Bottom + tpoint.y / TwipsPerPixelY) - temp.y / TwipsPerPixelY
  295.        sDc = GetDC(ByVal 0)
  296.        DrawFocusRect sDc, oldbox
  297.        DrawFocusRect sDc, tbox
  298.        d = ReleaseDC(0, sDc)
  299.        oldbox = tbox
  300. End Sub
  301. Private Sub EndFRDrag(x As Single, y As Single)
  302.     If IsMaximized = True Then Exit Sub
  303.     If IsMinimized = True Then Exit Sub
  304.        Dim tDc As Long
  305.        Dim sDc As Long
  306.        Dim d As Long
  307.        Dim newleft As Single
  308.        Dim newtop As Single
  309.        sDc = GetDC(ByVal 0)
  310.        DrawFocusRect sDc, oldbox
  311.        d = ReleaseDC(0, sDc)
  312.        newleft = x + fbox.Left * TwipsPerPixelX - dpoint.x
  313.        newtop = y + fbox.Top * TwipsPerPixelY - dpoint.y
  314.        Me.Move newleft, newtop
  315.        cmdDummy.SetFocus
  316. End Sub
  317. Private Sub DrawCaption(sCaption As String)
  318.     lblFormCaption.Caption = sCaption
  319. End Sub
  320. Private Sub ReSize()
  321.     lineBorder1.BorderColor = vb3DHighlight
  322.     lineBorder2.BorderColor = vb3DHighlight
  323.     lineBorder3.BorderColor = vb3DShadow
  324.     lineBorder4.BorderColor = vb3DShadow
  325.     lineBorder1.Y2 = Me.Height
  326.     lineBorder2.X2 = Me.Width
  327.     lineBorder3.X1 = Me.Width - 10
  328.     lineBorder3.X2 = Me.Width - 10
  329.     lineBorder3.Y1 = 0
  330.     lineBorder3.Y2 = Me.Height
  331.     lineBorder4.X1 = 0
  332.     lineBorder4.X2 = Me.Width - 10
  333.     lineBorder4.Y1 = Me.Height - 10
  334.     lineBorder4.Y2 = Me.Height - 10
  335.     picTitleBar.Width = Me.Width - 25
  336.     imgCloseForm.Left = picTitleBar.Width - imgCloseForm.Width - GT_SPACERVAL
  337.     imgMaximize.Left = picTitleBar.Width - imgCloseForm.Width - imgMaximize.Width - GT_SPACERVAL * 2
  338.     If ButtonsCount <> 2 Then
  339.         imgMinimize.Left = picTitleBar.Width - imgCloseForm.Width - imgMaximize.Width - imgMinimize.Width - GT_SPACERVAL * 2
  340.     Else
  341.         imgMinimize.Left = picTitleBar.Width - imgCloseForm.Width - imgMinimize.Width - GT_SPACERVAL * 2
  342.     End If
  343.     Select Case GT_HOW
  344.         Case "TtoB"
  345.             MakeGrad picTitleBar, 0, GT_RED, GT_GREEN, GT_BLUE, -3, -3, -3
  346.         Case "LtoR"
  347.             MakeGrad picTitleBar, 1, GT_RED, GT_GREEN, GT_BLUE, -3, -3, -3
  348.         Case Else
  349.             MakeGrad picTitleBar, 1, GT_RED, GT_GREEN, GT_BLUE, -3, -3, -3
  350.     End Select
  351. End Sub
  352.